/* eslint-disable no-undef */
import axios from 'axios'
import Message from 'element-ui'
import request from '@/utils/request'
/**
 * 获取职位类别
 */
export const getCategoryList = () => {
  try {
    const response = axios.get('http://localhost:3000/category')
    return response
  } catch (error) {
    Message({ type: 'error', message: '获取职位类别失败' })
    return Promise.reject(error)
  }
}
// 左树右表的左右联动
export const getJobList = (categoryId) => {
  try {
    const response = axios.get('http://localhost:3000/job', {
      params: {
        categoryId
      }
    })
    return response
  } catch (error) {
    Message({ type: 'error', message: '获取职位列表失败' })
    return Promise.reject(error)
  }
}
// 新增数据提交
export const addJob = (data) => {
  try {
    const response = axios.post('http://localhost:3000/job', data)
    return response
  } catch (error) {
    Message({ type: 'error', message: '新增职位失败' })
    return Promise.reject(error)
  }
}
// 删除数据接口
export const delJob = (id) => {
  try {
    const response = axios.delete(`http://localhost:3000/job/${id}`)
    return response
  } catch (error) {
    Message({ type: 'error', message: '删除职位失败' })
    return Promise.reject(error)
  }
}
// 获取权限列表接口方法
export const getPermissionList = () => {
  return request.get('/sys/permission')
}
// 添加权限
export const addPermission = (data) => {
  return request.post('/sys/permission', data)
}
// 删除权限
export const delPermission = (id) => {
  return request.delete(`/sys/permission/${id}`)
}
// 获取权限详情
export const getPermissionDetail = (id) => {
  return request.get(`/sys/permission/${id}`)
}
// 修改权限
export const updatePermission = (data) => {
  return request.put(`/sys/permission/${data.id}`, data)
}
